* Harmonize company names (some companies have different names but are the same
* company. Most of these are small string differences, but some are companies 
* that changed their name, often after an acquisition).
replace companyName = trim(subinstr(companyName, ",", "", .))
replace companyName = subinstr(companyName, ".", "", .)
replace companyName = subinstr(companyName, "INCORPORATED", "INC",.)

* Typos
replace companyName = "CREALTA HOLDINGS PTY LTD" if regexm(companyName, "CREATA HOLDINGS PTY LTD")
replace companyName = "SANPOWER GROUP" if regexm(companyName, "SUNPOWER GROUP")

* Small edits for consistency across datasets
replace companyName = "HORIZON THERAPEUTICS PLC" if regexm(companyName, "HORIZON THERAPEUTICS")
replace companyName = subinstr(companyName, "COLLEGIUM PHARMACEUTICAL INC", "COLLEGIUM PHARMACEUTICALS",.)
replace companyName = subinstr(companyName, "COLUMBIA LABORATORIES INC", "COLUMBIA LAB",.)
replace companyName = subinstr(companyName, "GRACEWAY PHARMACEUTICALS INC", "GRACEWAY PHARMACEUTICALS LLC",.)
replace companyName = subinstr(companyName, "KING PHARM INC", "KING PHARMACEUTICALS LLC",.)
replace companyName = subinstr(companyName, "KING PHARMACEUTICALS LLC", "KING PHARM",.)
replace companyName = subinstr(companyName, "NAPO PHARMACEUTICALS INC", "NAPO PHARMACEUTICALS",.)										  										  
replace companyName = subinstr(companyName, "PAR PHARMACEUTICAL COMPANIES INC", "PAR PHARMACEUTICAL COS INC",.)	
replace companyName = subinstr(companyName, "SHIRE PLC", "SHIRE US INC",.)
replace companyName = subinstr(companyName, "UCB INC", "UCB SA",.)
replace companyName = subinstr(companyName, "ACTAVIS ELIZABETH LLC", "ACTAVIS PLC",.)
replace companyName = subinstr(companyName, "BRISTOL-MYERS SQUIBB COMPANY", "BRISTOL-MYERS SQUIBB",.)
replace companyName = subinstr(companyName, "ACTIENT HOLDINGS LLC", "ACTIENT PHARMACEUTICALS LLC",.) //	This one I am not 100% sure about
replace companyName = subinstr(companyName, "JHP GROUP HOLDINGS INC", "JHP PHARMACEUTICALS LLC", .)
replace companyName = subinstr(companyName, "ACTAVIS GROUP EHF", "ACTAVIS PLC", .)



*** Companies that changed names

* Valeant changed its name to Bausch, but its most important activity in our 
* data came under the name Valeant
replace companyName = subinstr(companyName, "BAUSCH HEALTH COS INC", "VALEANT PHARMACEUTICALS", .)

* Watson bought Actavis PLC in 2012, and took on the name Actavis. It then 
* bought Allergan in 2014, and subsequently changed its name to Allergan. 
* Finally, it spun off its generic arm, named Actavis Inc to TEVA.
* To minimize confusion, we keep the original company name (WATSON 
* PHARMACEUTICALS) to indicate the main company.
replace companyName = subinstr(companyName, "ALLERGAN PLC", "WATSON PHARMACEUTICALS", .)
replace companyName = subinstr(companyName, "ACTAVIS PLC", "WATSON PHARMACEUTICALS", .) if quarter > tq(2012q3)
replace companyName = subinstr(companyName, "ALLERGAN INC", "WATSON PHARMACEUTICALS", .) if quarter > tq(2015q1)

* SKYEPHARMA changed its name to PACIRA after its acquisition of DEPODUR (and 
* became a private company)
* (https://investor.pacira.com/news-releases/news-release-details/skyepharma-inc-now-private-pharmaceutical-company-announces-name)
replace companyName = subinstr(companyName, "SKYEPHARMA PLC", "PACIRA PHARMACEUTICALS INC", .)

* Abbott spun its research-based pharmaceutical business into Abbvie in 2012
replace companyName = subinstr(companyName, "ABBOTT LABORATORIES", "ABBVIE INC", .)

* Dermik is a subsidiary of SANOFI
replace companyName = "SANOFI" if regexm(companyName, "DERMIK LABORATORIES INC")

* Hi-Tech is the same company as ECR Pharmaceuticals
replace companyName = "ECR PHARMACEUTICALS" if regexm(companyName, "HI-TECH PHARMACAL CO INC")

